/*
 * Copyright (C) 2000-2007 Wang Pengcheng <wpc0000@163.com>
 * Licensed to the Wang Pengcheng under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The LGPL licenses this file to You under the GNU Lesser General Public
 * Licence, Version 2.0  (the "License"); you may not use this file except in
 * compliance with the License.  You may obtain a copy of the License at
 *
 *     http://www.gnu.org/licenses/lgpl.txt
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
//28 Aug 2007
package cn.edu.whu.data;

import java.util.*;

import cn.edu.whu.data.Data;;

/**
 * The list of the class-field.
 * 
 * @author wpc
 *
 */
public class DataList implements Iterable<Data>{

	private List<Data> list = new ArrayList<Data>();

	public DataList(){

	}
	
	public boolean add(Data d){
		try{
			list.add(d);
			return true;
		}catch(Exception e){
			e.printStackTrace();
			return false;
		}
	}
	
	public boolean add(String type,String name,boolean only){
		try{
			add(new Data(type,name,only));
			return true;
		}catch(Exception e){
			e.printStackTrace();
			return false;
		}
	}
	
	public Data get(int index){
		return list.get(index);
	}
	
	public Data getByName(String name){
		Data d=null;
		for(int i=0;i<list.size();i++){
			if(  ((list.get(i)).getName()).equals(name) ){
				d = list.get(i);
				break;
			}
		}
		return d;
	}
	
	public int size(){
		return list.size();
	}

	public Iterator<Data> iterator() {
		// TODO Auto-generated method stub
		return list.iterator();
	}

}
